package studentManagent;

import java.util.Arrays;
import java.util.Scanner;

public class StudentManagent {

	Student[] stus = new Student[20];
	int count;

	Scanner scan = new Scanner(System.in);

	// 1添加学生
	public boolean add(Student student) {
		// 班级 学号 姓名 成绩
		// TODO 任浩
		if (count < 20) {
			stus[count] = student;
			count++;
			return true;
		} else {
			return false;
		}

	}

	// 2.根据学号删除学生
	// TODO 仲福维
	public boolean remove(int student) {

		boolean isDelet = false;
		student = scan.nextInt();
		for (int i = 0; i < count; i++) {
			if (stus[i].id == student) {
				for (int j = i + 1; j < count; j++) {
					stus[j - 1] = stus[j];
					stus[count - 1] = null;
					count--;
				}
				isDelet = true;
			}
		}
		return isDelet;
	}

	// 3.根据学号查询学生
	public Student getById(int student) {
		// TODO 张爽
		for (int i = 0; i < count; i++) {

			if (stus[i].id == student) {
				Student stuInfo = new Student();

				return stus[i];
			}
		}
		return null;
	}

	// 4.根据班级查询学生
	public void getByClassName(String student) {
		// TODO 东航
		String className = scan.next();
		for (int i = 0; i < count; i++) {
			if (className.equals(stus[i].className)) {
				System.out.println("学生姓名：" + stus[i].name);
				System.out.println("学号：" + stus[i].id);
				System.out.println("成绩：" + stus[i].score);
			}
		}
	}

	// 5.根据姓名查询学生
	public Student getByName(String student) {
		// TODO 任浩
		System.out.print("请输入学生姓名:");
		String checkName = scan.next();
		for (int i = 0; i < count; i++) {
			if (checkName.equals(stus[i].name)) {
				System.out.println("学生姓名：" + stus[i].name);
				System.out.println("班级：" + stus[i].className);
				System.out.println("学号：" + stus[i].id);
				System.out.println("成绩：" + stus[i].score);
				return stus[i];
			}
		}
		return null;
	}

	// 6.查询所有学生
	// TODO 东航
	public Student[] listAll() {

		for (int i = 0; i < count; i++) {
			System.out.println("学生姓名：" + stus[i].name);
			System.out.println("班级：" + stus[i].className);
			System.out.println("学号：" + stus[i].id);
			System.out.println("成绩：" + stus[i].score);
		}
		return null;
	}

	// 7.查询所有不及格学生
	public Student getByScoreNotPass() {
		// TODO 张爽
		for (int i = 0; i < stus.length; i++) {
			if (stus[i].score <= 60) {
				return stus[i];
			}
		}
		return null;
	}

	// 8.从高到底返回排序后的学生数组
public String sortByScore() {
	//TODO 仲福维
	System.out.println("===学生成绩排名===");
	for (int i = 0; i < count; i++) {
		
		
			if(stus[i].score<stus[i+1].score) {
				Student temp = stus[i+1];
				stus[i]= stus[i+1];
				stus[i+1]= temp;
		System.out.println(stus[i]);
			}
		}
	return null;
	
	}

}
